<?php

namespace App\Repository;

use App\Exceptions\BusinessException;
use App\Common\Constant;
use App\Common\ResponseCode;
use App\Models\Base\Files;
use App\Models\Base\Group;
use App\Models\Goods\AttributesValue;
use App\Models\Goods\FileBind;
use App\Models\Goods\Goods;
use App\Models\Goods\Products;
use App\Models\Role\Role;
use App\Models\User\User;

/**
 * 群组数据仓储类
 *
 * @package App\Http\Repository
 * @author WangBin
 * @mail: <849850352@qq.com>
 */
class GroupRepository extends BaseRepository
{
    /**
     * 获取群组
     *
     * @param int $groupId
     * @return
     */
    public function getById(int $groupId)
    {
        return Group::query()->where('group_id', $groupId)->first();
    }

    /**
     * 删除群组
     *
     * @param int $groupId
     * @return array
     */
    public function delete(int $groupId)
    {
        return Group::query()->where('is_system', 0)->where('group_id', $groupId)->delete();
    }

    /**
     * 获取群组列表
     *
     * @param array $filter
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function getList(array $filter = [])
    {
        $query = Group::query();
        if(!empty($filter['type'])) {
            $query->where('type', $filter['type']);
        }
        if(isset($filter['is_active'])) {
            $query->where('is_active', $filter['is_active']);
        }
        return $query;
    }
}
